$(function () {
    var options = {
        modalName: "分类",
        url: "/render/categoryManager/list",
        getInfoUrl: "/render/categoryManager/get/{id}",
        updateUrl: "/render/categoryManager/edit",
        removeUrl: "/render/categoryManager/remove",
        createUrl: "/render/categoryManager/add",
        searchUrl: "/render/categoryManager/search",
        pageNumber:1,
        pageSize:7,
        columns: [
            {
                checkbox: true,
                formatter:checkboxMatter
            }, {
                field: 'id',
                title: 'ID',
                align: "center",
                width: '50px',
                class:"colStyle",
                sortable : true,
                formatter:paramsMatter
            }, {
                field: 'parent_id',
                title: '父类',
                align: "center",
                width: '100px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'name',
                title: '类别名称',
                align: "center",
                width: '88px',
                class:"colStyle",
                // sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'status',
                title: '类别状态',
                align: "center",
                width: '88px',
                sortable : true,
                cellStyle:formatTableUnit,
                // formatter:paramsMatter
                formatter: function (value) {
                    value = (value==1) ? '上线' : '下线';
                    var span=document.createElement('span');
                    span.setAttribute('title',value);
                    span.innerHTML = value;
                    return span.outerHTML;
                }
            }, {
                field: 'sort_order',
                title: '排序编号',
                align: "center",
                width: '88px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'create_time',
                title: '创建时间',
                width: '88px',
                align: "center",
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'update_time',
                title: '更新时间',
                width: '88px',
                align: "center",
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'operate',
                title: '操作',
                align: "center",
                width: '100px',
                formatter: operateFormatter //自定义方法，添加操作按钮
            }
        ]
    };
    // 初始化table组件
    var table = new Table(options);
    table.init();

    //search按钮绑定查询事件
    $('#btnSearch').on('click', function () {
        var searchtext = {
            name: $("#search-name").val(),
            parent_id: $("#search-parent_id").val(),
            id: $("#search-id").val()
        };
        console.log(""+$("#search-name").val());
        if($("#search-name").val() === ""&&$("#search-search-parent_id").val() === ""&&$("#search-id").val() === ""){
            postParams(options.url,options.onExpandRow,options,options.rowStyle,options.columns,null,true);
        }else {
            postParams(options.searchUrl,options.onExpandRow,options,options.rowStyle,options.columns,JSON.stringify(searchtext),false);
        }
    });

    $(".close,.btn-default").on("click",function () {
        $(".modal").css("display","");
        $(".modal").removeClass("in");
        $(".modal-backdrop").removeClass("in");
    });
});